<!--
  图片查看弹窗
  Created by liujialing
  使用说明：
  <img-list v-model="dialogVisible" :img-list="imgArr" :img-index="imgIndex"></img-list>
  字段说明：
    v-model(Boolean): 弹窗显隐
    img-list(Array): 图片列表([{url: 'imgurl'}])
    img-index(Number): 起始索引(可不传)
-->

<template>
  <div>
    <el-dialog title="查看图片" :visible.sync="dialogVisible" width="50%">
      <el-carousel ref="swipe" indicator-position="outside" :autoplay="false" height="500px">
        <el-carousel-item v-for="(item, index) in imgList" :key="index">
          <img :src="baseUrl + '/' + item.url" class="swipe-img">
        </el-carousel-item>
      </el-carousel>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'imgList',
  props: {
    imgList: {
      type: Array,
      default: () => []
    },
    value: {
      type: Boolean,
      default: false
    },
    imgIndex: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      baseUrl: process.env.BASE_FILE_URL,
      dialogVisible: this.value,
    }
  },
  watch: {
    value(val) {
      this.dialogVisible = val;
      if(this.$refs.swipe) {
        this.$refs.swipe.setActiveItem(this.imgIndex);
      }
    },
    dialogVisible(val) {
      this.$emit('input', val);
    }
  }
}
</script>

<style lang="scss" scoped>
.swipe-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
</style>

